package Scuttlebutt;

import java.awt.event.*;
import java.lang.*;
import java.io.*;

public class MouseEventHandler implements MouseListener 
{
	Scuttlebutt parent = null;
	
	public MouseEventHandler(Scuttlebutt parent)
	{
		this.parent = parent;
	}

	public void mouseClicked(MouseEvent m0)
	{
		if(m0.getButton() == m0.BUTTON1){
			if(m0.getClickCount() == 2){
				Object o = parent.getProject().getTree().getLastSelectedPathComponent();
				
				if (o instanceof SortableNode ) {
					SortableNode node = (SortableNode)parent.getProject().getTree().getLastSelectedPathComponent();
			    	if((node != null) && (node.getNodePath() != null)){
				    	File path = new File(node.getNodePath());
				    	if(path != null){
					    	if(path.isFile()){
					   		 	parent.getEditPane().Open(path.getPath());
					   		 	parent.SaveProject();
					    	}
				    	}
				    	
				    	path = null;
			    	}
				}
			}
			
			
		}else if(m0.getButton() == m0.BUTTON2){
		}else if(m0.getButton() == m0.BUTTON3){
			parent.getProject().getTree().setSelectionPath(parent.getProject().getTree().getPathForLocation(m0.getX(), m0.getY()));
			Object o = parent.getProject().getTree().getLastSelectedPathComponent();
			if (o instanceof FolderNode ) {
				FolderPopupMenu pop = new FolderPopupMenu(parent, m0.getX(), m0.getY());
				pop.show(parent.getProject().getTree(), m0.getX(), m0.getY());
			} else if (o instanceof URLNode ) {
				URLPopupMenu pop = new URLPopupMenu(parent);
				pop.show(parent.getProject().getTree(), m0.getX(), m0.getY());
			} else if (o instanceof SortableNode ) {
				FilePopupMenu pop = new FilePopupMenu(parent, m0.getX(), m0.getY());
				pop.show(parent.getProject().getTree(), m0.getX(), m0.getY());
			}
		}
	}

	public void mouseEntered(MouseEvent m0)
	{
	}

	public void mouseExited(MouseEvent m0)
	{
	}

	public void mousePressed(MouseEvent m0)
	{
	}

	public void mouseReleased(MouseEvent m0)
	{
	}
}

